package com.alipay.app.groupmeal.standard.service;

import static com.tencent.iot.explorer.device.java.data_template.TXDataTemplateConstants.TemplateSubTopic.SERVICE_DATA_STREAM_TOPIC;

import static java.lang.Thread.sleep;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.alipay.app.groupmeal.standard.constant.ConfigConstant;
import com.alipay.app.groupmeal.standard.mqtt.SelfDownStreamCallBack;
import com.alipay.app.groupmeal.standard.mqtt.SelfMqttActionCallBack;
import com.alipay.app.groupmeal.standard.mqtt.SelfMqttLogCallBack;
import com.alipay.iot.sdk.utils.SystemUtils;
import com.tencent.iot.explorer.device.android.app.data_template.DataTemplateSample;
import com.tencent.iot.explorer.device.android.app.gateway.GatewaySample;
import com.tencent.iot.hub.device.java.core.common.Status;

public class MqttService extends Service {
    private static final String TAG = "MqttService";


    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onCreate() {
        System.out.println("onCreate");
        //创建连接
        DataTemplateSample mDataTemplateSample = new DataTemplateSample(this,
                ConfigConstant.brokerURL,
                ConfigConstant.productID,
                SystemUtils.getSerialNumber(),
                ConfigConstant.devPSK, true,
                new SelfMqttLogCallBack(), new SelfMqttActionCallBack(),
                ConfigConstant.jsonFileName, new SelfDownStreamCallBack());
        mDataTemplateSample.connect();


        try {
            sleep(1000);
        } catch (Exception e) {

        }

        //开启订阅
        mDataTemplateSample.subscribeTopic();

    }

    @Override
    public void onDestroy() {
        System.out.println("onDestroy");

    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        System.out.println("onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }
}